package com.example.wastes.message.controller;


import com.example.wastes.common.pojo.Message;
import com.example.wastes.common.util.R;
import com.example.wastes.message.mapper.MessageMapper;
import com.example.wastes.message.service.MessageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class MessageController {
    @Autowired
    private MessageService messageService;
    @Autowired
    private MessageMapper messageMapper;
    @GetMapping("/getAllMessage")
    @ApiOperation("信息表查询所有")
    public R getAllMessage(){
        return new R(true,messageService.list());
    }
    @PostMapping("/saveMessage")
    @ApiOperation("添加信息表")
    public R saveMessage(@RequestBody Message message){
        return new R(messageService.save(message));
    }
    @PutMapping("/updateMessage")
    @ApiOperation("修改信息表")
    public R updateMessage(@RequestBody Message message){
        return new R(messageService.updateById(message));
    }
    @DeleteMapping("/deleteMessage")
    @ApiOperation("删除信息表")
    public R deleteMessage(Integer id){
        return new R(messageService.removeById(id));
    }
    @GetMapping("/findMessageMerge")
    @ApiOperation("信息表和用户表的关联")
    public R findMessageMerge(Integer id){
        return new R(true,messageService.findMessageMerge(id));
    }
    @GetMapping("/findMessageMerge1")
    @ApiOperation("信息表和用户表的关联只显示信息表")
    public R findMessageMerge1(Integer userid){
        return new R(true,messageService.findMessageMerge1(userid));
    }
    //模糊查询
    @GetMapping("findMessageName")
    @ApiOperation("通过电话号码查所有")
    public R findMessageName(String phones){
        return new R(true,messageService.findMessageName(phones));
    }
    @GetMapping("/saveMessage")
    public String saveMessage(String address,String number,String name,String phone,String userid){
        System.out.println(address);
        System.out.println(number);
        System.out.println(name);
        System.out.println(phone);
        int resultCount = messageMapper.saveMessage(address,number,name,phone,userid);
        if (resultCount == 0){
            return "插入失败";
        }
        return "插入成功";
    }
}
